{#
(C) Copyright 2011 Jose Blanco <jose.blanco[a]vikuit.com>

This file is part of "vikuit".

"vikuit" is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

"vikuit" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with "vikuit".  If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "layouts/module-layout.html" %}
{% block head %}
	<link rel="alternate" type="application/rss+xml" title="{{ _('Latest articles by %s')|format(this_user.nickname) }}" href="/feed/module/user/{{ this_user.nickname }}" />
{% endblock %}

{% block title %} {{ _('User') }} {{ this_user.nickname }} {% endblock %}

{% block rightSidebar %}
	<div class="box">
		<div class="vk_title">{{ _('RSS') }}</div>
		<ul><li><a href="/feed/module/user/{{ this_user.nickname }}"><img src="/static/images/feed.png" alt="feed" class="icon" /> {{ _('Latest articles by %s')|format(this_user.nickname) }}</a></li></ul>
	</div>
{% endblock %}

{% block content %}
	<div class="grid_9 alpha omega">
		<div class="info">
			<h1>{{ _('User') }} {{ this_user.nickname }}</h1>
			<p class="options">
				{% if canadd %}
					{% if is_contact %}
						<span><a id="contact" href="/module/user.contact?user_to={{ this_user.nickname }}&amp;auth={{ auth }}">
							<img src="/static/images/delete.png" alt="" class="icon" /> {{ _('Delete contact') }}</a></span>
					{% else %}
						<span><a id="contact" href="/module/user.contact?user_to={{ this_user.nickname }}&amp;auth={{ auth }}">
							<img src="/static/images/add.png" alt="" class="icon" /> {{ _('Add to contacts') }}</a></span>
					{% endif %}
				{% endif %}
				{% if user and this_user.nickname != user.nickname %}
					| <a href="/module/message.edit?user_to={{ this_user.nickname }}"><img src="/static/images/page_white_edit.png" alt="" class="icon" /> {{ _('Send message to %s')|format(this_user.nickname) }}</a>
				{% endif %}
				{% if user.rol == 'admin' %}
					{{ _('mail') }}: <strong><a href="mailto:{{ this_user.email }}">{{ this_user.email }}</a></strong>
				{% endif %}
			</p>
		</div>

	</div>
	<div class="clear">&nbsp;</div>
	<div class="grid_9 alpha omega">
		<div class="grid_2 alpha">
			{% if this_user.image_version %}
				<img src="/images/user/avatar/{{ this_user.nickname }}/{{ this_user.image_version }}" alt="{{ this_user.nickname }}" />
			{% else %}
				<img src="/images/user/avatar/{{ this_user.nickname }}" alt="{{ this_user.nickname }}" />
			{% endif %}
		</div>
		<div class="grid_7 omega">
			{% if this_user.personal_message %}<h6>{{ this_user.personal_message|escape }}</h6>{% endif %}
			<ul>
				{% if this_user.real_name %}<li>{{ _('Full name') }}: <strong>{{ this_user.real_name|escape }}</strong></li> {% endif %}
				{% if this_user.country %}<li>{{ _('Country') }}: <strong>{{ this_user.country|escape }}</strong></li> {% endif %}
				{% if this_user.city %}<li>{{ _('City') }}: <strong>{{ this_user.city|escape }}</strong></li> {% endif %}
				<li>{{ _('Registered %s ago')|format(this_user.creation_date|relativize) }}</li>
			</ul>
		</div>
	</div>
	<div class="clear">&nbsp;</div>
	<hr class="separator"/>
	<div class="grid_9 alpha omega">
		<strong>{{ _('About') }} {{ this_user.nickname }}:</strong><br/>
		{% if this_user.about_user %}
			{{ this_user.about_user|escape }}
		{% else %}
			{{ _('No description in profile.') }} {% if user.nickname == this_user.nickname %} <a href="/module/user.edit">{{ _('Edit your profile') }}</a>{% endif%}
		{% endif %} 
		{% if links %}
			<hr class="separator"/>
			<h4>{{ _('Links') }}</h4>
			{% for link in links %}
				<div class="grid_3 center {% if loop.index % 3 == 0 %}omega{% elif loop.index % 3 == 1 %}alpha{% endif %}">
					{{ link.0 }}:<br/>
					{% if link.0 == 'blog' %}
						<a href="{{ link.1 }}" target="_blank"><img src="http://api.thumbalizr.com/?url={{ link.1 }}&amp;width=128" alt=""></a>
					{% else %}
						{% if link.0 == 'linkedin' %}
							<a href="{{ link.1 }}" target="_blank"><img src="http://www.linkedin.com/img/webpromo/btn_myprofile_160x33.gif" alt="{{ _('Linkedin profile') }}"></a>
						{% endif %}
						{% if link.0 == 'ohloh' %}
							  <a href="{{link.1}}"><img src="{{link.1}}/widgets/account_detailed.gif" width="191" height="35" alt="{{ _('Ohloh profile') }}"></a>
						{% endif %}
					{% endif %}
				</div>
			{% endfor %}
			<div class="clear">&nbsp;</div>
		{% endif %}
		{% if im_addresses and user %}
			<hr class="separator"/>
			<h4>{{ _('Contact addresses') }}: </h4>
			{% for im_address in im_addresses %}
				<div class="grid_3 center {% if loop.index % 3 == 0 %}omega{% elif loop.index % 3 == 1 %}alpha{% endif %}">
					{{ im_address.0}}:<br/>
					<strong>{{im_address.1}}</strong>
				</div>
			{% endfor %}

		{% endif %}

	</div>
	<div class="clear">&nbsp;</div>
	<div class="grid_9 alpha omega">
		{% if articles %}
		<hr class="separator"/>
		<h4>{{ _('Latest articles') }}</h4>
		<table class="grid">
			<thead>
				<tr>
					<th class="left">{{ _('Title') }}</th>
					<th class="right">{{ _('Comments') }}</th>
					<th class="right">{{ _('Ratings average') }}</th>
				</tr>
			</thead>
			<tbody>
		{% for article in articles %}
			<tr {% if loop.index % 2 == 0 %}class="even"{% endif %}>
				<td class="left">
					<strong><a href="/module/article/{{ article.url_path }}">{{ article.title|escape }}</a></strong>
				</td>
				<td>
					{{ article.responses }}
				</td>
				<td>
					<p class="rating star{{ article.rating_average }}" style="float:right">&nbsp;</p>&nbsp;&nbsp;&nbsp;
				</td>
			</tr>
		{% endfor %}
			</tbody>
		</table>
		<p class="more"><a href="/module/user.articles/{{ this_user.nickname }}">{{ _('Check all articles') }} »</a></p>
		{% endif %}
		{% if contacts %}
		<hr class="separator"/>
		<h4>{{ _('Contacts') }}</h4>
		{% for contact in contacts %}
			<div class="grid_1 {% if loop.index % 9 == 0 %}omega{% elif loop.index % 9 == 1 %}alpha{% endif %}">
			<p class="center">
				<a href="/module/user/{{ contact.user_to_nickname }}">
					<img src="/images/user/thumbnail/{{ contact.user_to_nickname }}"
						alt="{{ contact.user_to_nickname }}"
						title="{{ contact.user_to_nickname }}" />
				</a>
			</p>
			</div>
			{% if loop.index % 9 == 0 %}
			<div class="clear">&nbsp;</div>
			{% endif %}
		{% endfor %}
		<div class="clear">&nbsp;</div>
		<p class="more">
			<a href="/module/user.contacts/{{ this_user.nickname }}">{{ _('Check all contacts') }} »</a>
		</p>
		{% endif %}
		{% if communities %}
		<hr class="separator"/>
		<h4>{{ _('Communities') }}</h4>
		{% for community in communities %}
			<div class="grid_1 {% if loop.index % 9 == 0 %}omega{% elif loop.index % 9 == 1 %}alpha{% endif %}">
			<p class="center">
				<a href="/module/community/{{ community.community_url_path }}">
					<img src="/images/community/thumbnail/{{ community.community.key().id() }}"
						alt="{{ community.title }}"
						title="{{ community.community_title }}" />
				</a>
			</p>
			</div>
			{% if loop.index % 9 == 0 %}
			<div class="clear">&nbsp;</div>
			{% endif %}
		{% endfor %}
		<div class="clear">&nbsp;</div>
		<p class="more">
			<a href="/module/user.communities/{{ this_user.nickname }}">{{ _('Check all communities') }} »</a>
		</p>
		{% endif %}
	</div>
	<div class="clear">&nbsp;</div>
{% endblock %}

{% block javascript %}

<script type="text/javascript" charset="utf-8">
	{% if canadd %}
	function add_contact() {
		var contact = $('contact');
		var parent = $(contact.parentNode);
		Element.observe(contact, 'click', function(e) {
			href = contact.href + '&x=1';
			parent.innerHTML = '<img class="icon" src="/static/images/spinner.gif" />';
			new Ajax.Request(href, {
				method: 'get',
				onSuccess: function(transport, json) {
					var action = transport.responseText.evalJSON().action;
					if(action == 'deleted') {
						parent.innerHTML = '<a id="contact" href="/module/user.contact?user_to={{ this_user.nickname }}&amp;auth={{ auth }}">'+
							'<img src="/static/images/add.png" alt="{{ _('Add to contacts') }}" class="icon" /> {{ _('Add to contacts') }}</a>';
					} else {
						parent.innerHTML = '<a id="contact" href="/module/user.contact?user_to={{ this_user.nickname }}&amp;auth={{ auth }}">'+
						'<img src="/static/images/delete.png" alt="{{ _('Delete contact') }}" class="icon" /> {{ _('Delete contact') }}</a>';
					}
					add_contact();
				},
				onFailure: function() {
					parent.innerHTML = "{{ _('There was an error') }} :(";
				}
			});
			Event.stop(e);
		});
	}
	add_contact();
	{% endif %}
</script>
{% endblock %}
